import { LocationQueryValue } from 'vue-router'
import { getArticle } from '@/https/api'
import { useGetTitltes } from './getTitles'
import { ElNotification } from 'element-plus'

export const useGetArticle = (id: LocationQueryValue, getValue: Function, getTitles: Function) => {   //getValue与getTitles为外部传来的函数，用于回传
    getArticle(id).then(({ data }) => {   //发送请求获取文章
        getValue(data)          //将文章内容回传
        useGetTitltes(getTitles)//解析视图中的标题，将通过getTitles回传
    }).catch((err) => {
        ElNotification({
            title: 'Error',
            message: err,
            type: 'error',
        })
    })

}